package com.ustarlink.learnlauncher;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.view.View;
import android.widget.AdapterView;

/**
 * Created by cfm on 16-3-11.
 */
public class DrawerClickListener implements AdapterView.OnItemClickListener {
    Context mContext;
    MainActivity.Pac[] pacsForAdapter;
    PackageManager pmForListener;

    public DrawerClickListener(Context c, MainActivity.Pac[] pacs, PackageManager pm) {
        mContext = c;
        pacsForAdapter = pacs;
        pmForListener = pm;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if (MainActivity.appLaunchable) {
            Intent launcherIntent = pmForListener.getLaunchIntentForPackage(pacsForAdapter[position].name);
            mContext.startActivity(launcherIntent);
        }
    }
}
